<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" size="small" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="姓名" prop="name"
                :rules="[
                  {required: true, message:'姓名不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.name" placeholder="请填写姓名"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="岗位" prop="post"
                :rules="[
                  {required: true, message:'岗位不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.post" placeholder="请填写岗位"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="基本工资" prop="basePay"
                :rules="[
                 ]">
              <el-input v-model="inputForm.basePay" placeholder="请填写基本工资"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="岗位工资" prop="postWage"
                :rules="[
                 ]">
              <el-input v-model="inputForm.postWage" placeholder="请填写岗位工资"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="绩效工资" prop="meritPay"
                :rules="[
                 ]">
              <el-input v-model="inputForm.meritPay" placeholder="请填写绩效工资"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="应发合计" prop="laballot"
                :rules="[
                 ]">
              <el-input v-model="inputForm.laballot" placeholder="请填写应发合计"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工龄工资" prop="seniorityPay"
                :rules="[
                 ]">
              <el-input v-model="inputForm.seniorityPay" placeholder="请填写工龄工资"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="餐费补助" prop="mealAllowance"
                :rules="[
                 ]">
              <el-input v-model="inputForm.mealAllowance" placeholder="请填写餐费补助"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="交通补助" prop="trafficAllowance"
                :rules="[
                 ]">
              <el-input v-model="inputForm.trafficAllowance" placeholder="请填写交通补助"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="省外津贴" prop="outsideProvinceAllowance"
                :rules="[
                 ]">
              <el-input v-model="inputForm.outsideProvinceAllowance" placeholder="请填写省外津贴"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="全勤奖" prop="attendanceBonus"
                :rules="[
                 ]">
              <el-input v-model="inputForm.attendanceBonus" placeholder="请填写全勤奖"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="业务提成" prop="commission"
                :rules="[
                 ]">
              <el-input v-model="inputForm.commission" placeholder="请填写业务提成"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="出差天数" prop="travelDays"
                :rules="[
                 ]">
              <el-input v-model="inputForm.travelDays" placeholder="请填写出差天数"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="请假天数" prop="leaveDays"
                :rules="[
                 ]">
              <el-input v-model="inputForm.leaveDays" placeholder="请填写请假天数"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="实际出勤天数" prop="actualAttendanceDays"
                :rules="[
                 ]">
              <el-input v-model="inputForm.actualAttendanceDays" placeholder="请填写实际出勤天数"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="应出勤天数" prop="attendanceDays"
                :rules="[
                 ]">
              <el-input v-model="inputForm.attendanceDays" placeholder="请填写应出勤天数"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="基本养老" prop="provideAged"
                :rules="[
                 ]">
              <el-input v-model="inputForm.provideAged" placeholder="请填写基本养老"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="基本医疗" prop="medicalTreatment"
                :rules="[
                 ]">
              <el-input v-model="inputForm.medicalTreatment" placeholder="请填写基本医疗"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="失业保险" prop="unemploymentInsurance"
                :rules="[
                 ]">
              <el-input v-model="inputForm.unemploymentInsurance" placeholder="请填写失业保险"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="住房公积金" prop="housingProvidentFund"
                :rules="[
                 ]">
              <el-input v-model="inputForm.housingProvidentFund" placeholder="请填写住房公积金"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="个人所得税" prop="individualIncomeTax"
                :rules="[
                 ]">
              <el-input v-model="inputForm.individualIncomeTax" placeholder="请填写个人所得税"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="宿舍使用费" prop="dormitoryUsageFee"
                :rules="[
                 ]">
              <el-input v-model="inputForm.dormitoryUsageFee" placeholder="请填写宿舍使用费"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="迟到扣款" prop="lateDeductions"
                :rules="[
                 ]">
              <el-input v-model="inputForm.lateDeductions" placeholder="请填写迟到扣款"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="旷工扣款" prop="absenteeismDeductions"
                :rules="[
                 ]">
              <el-input v-model="inputForm.absenteeismDeductions" placeholder="请填写旷工扣款"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="应发金额" prop="totalPayAmount"
                :rules="[
                 ]">
              <el-input v-model="inputForm.totalPayAmount" placeholder="请填写应发金额"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="实发金额" prop="finalPayingAmount"
                :rules="[
                 ]">
              <el-input v-model="inputForm.finalPayingAmount" placeholder="请填写实发金额"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="入职日期" prop="entryDate"
                :rules="[
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.entryDate"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="备注信息" prop="remarks"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="visible = false">关闭</el-button>
      <el-button size="small" type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          name: '',
          post: '',
          basePay: '',
          postWage: '',
          meritPay: '',
          laballot: '',
          seniorityPay: '',
          mealAllowance: '',
          trafficAllowance: '',
          outsideProvinceAllowance: '',
          attendanceBonus: '',
          commission: '',
          travelDays: '',
          leaveDays: '',
          actualAttendanceDays: '',
          attendanceDays: '',
          provideAged: '',
          medicalTreatment: '',
          unemploymentInsurance: '',
          housingProvidentFund: '',
          individualIncomeTax: '',
          dormitoryUsageFee: '',
          lateDeductions: '',
          absenteeismDeductions: '',
          totalPayAmount: '',
          finalPayingAmount: '',
          entryDate: '',
          remarks: ''
        }
      }
    },
    components: {
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建工资`
        } else if (method === 'edit') {
          this.title = '修改工资'
        } else if (method === 'view') {
          this.title = '查看工资'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/epc/wageschedule/wageSchedule/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.wageSchedule)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/epc/wageschedule/wageSchedule/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              this.loading = false
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
            })
          }
        })
      }
    }
  }
</script>